package com.zxy.demo.guava.eventbus;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.reflect.TypeToken;

import java.util.concurrent.Executors;

/**
 * TestEventBus.
 * 
 * Created by zxybird on 17/3/18.
 */
public class TestEventBus {

  public static void main1(String[] args) {
    // 定义一个事件总线
    // EventBus eventBus = new AsyncEventBus(Executors.newFixedThreadPool(10));
    EventBus eventBus = new EventBus();
    // 定义一个监听者
    EventListener1 listener1 = new EventListener1();
    EventListener2 listener2 = new EventListener2();
    // 将监听者注册到事件总线上
    eventBus.register(listener1);
    eventBus.register(listener2);
    // 事件总线发布事件
    eventBus.post(new TestEvent1(200));
    eventBus.post(new TestEvent1(300));
    eventBus.post(new TestEvent1(400));

    System.out.println("LastMessage:" + listener1.getLastMessage());
  }

  public static void main(String[] args) {
    // 定义一个事件总线
    // EventBus eventBus = new AsyncEventBus(Executors.newFixedThreadPool(10));
    EventBus eventBus = new EventBus();
    // 定义一个监听者
    EventListener3 listener3 = new EventListener3();
    // 将监听者注册到事件总线上
    eventBus.register(listener3);
    // 事件总线发布事件
    eventBus.post(1);
    eventBus.post(1L);

  }

  public static void main3(String[] args) {
    System.out.println(TypeToken.of(EventListener3.class).getTypes().rawTypes());
  }

}
